package com.wise.sample1.controller;

import com.wise.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
@Profile(value = "sample1")
public class UserController {

    @Autowired
    private KafkaTemplate<String, User> kafkaTemplate;//No bean这个警告是idea的误报

    @RequestMapping("/{id}")
    public String UserTest(@PathVariable Integer id, String name) {
        User user = new User();
        user.setName(name);
        user.setId(id);
        try {
            kafkaTemplate.send("my-replicated-topic", user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "send success!" + user.toString();
    }
}
